package org.amphiprion.diceroller.screens.animation;

import org.amphiprion.diceroller.TagObject;
import org.amphiprion.gameengine.Mesh;
import org.amphiprion.gameengine.animation.GameComponentAnimation;

import android.view.animation.Interpolator;

public class ScaleTranslate3DAnimation extends GameComponentAnimation {

	private float startScale;
	private float endScale;
	private float[] startCoord;
	private float[] endCoord;

	private Interpolator itp;
	private Mesh mesh;
	private TagObject tag;
	private boolean updateAlternate;

	public ScaleTranslate3DAnimation(Mesh mesh, boolean updateAlternate, long duration, long delay, float[] startCoord, float[] endCoord, float startScale, float endScale) {
		this.delay = delay;
		this.startScale = startScale;
		this.endScale = endScale;
		this.startCoord = startCoord;
		this.endCoord = endCoord;
		this.duration = duration;
		this.mesh = mesh;
		this.tag = (TagObject) mesh.getTagObject();
		this.updateAlternate = updateAlternate;
	}

	@Override
	protected float getInterpolatedProgress(float progress) {
		if (itp != null) {
			return itp.getInterpolation(progress);
		} else {
			return super.getInterpolatedProgress(progress);
		}
	}

	@Override
	protected void onUpdate(float progress) {
		if (updateAlternate) {
			tag.alternateScale = (endScale - startScale) * progress + startScale;
			tag.alternateCoordinate[0] = (endCoord[0] - startCoord[0]) * progress + startCoord[0];
			tag.alternateCoordinate[1] = (endCoord[1] - startCoord[1]) * progress + startCoord[1];
			tag.alternateCoordinate[2] = (endCoord[2] - startCoord[2]) * progress + startCoord[2];
		} else {
			mesh.scale = (endScale - startScale) * progress + startScale;
			mesh.X = (endCoord[0] - startCoord[0]) * progress + startCoord[0];
			mesh.Y = (endCoord[1] - startCoord[1]) * progress + startCoord[1];
			mesh.Z = (endCoord[2] - startCoord[2]) * progress + startCoord[2];
		}
	}

	@Override
	public void start() {
	}

	public void setInterpolation(Interpolator itp) {
		this.itp = itp;
	}

	public void finish() {
		this.duration = 0;
		onUpdate(1.0f);
	}

	@Override
	public void removeComponent() {
		// TODO Auto-generated method stub

	}
}
